home *** CD-ROM | disk | FTP | other *** search
- <?xml version="1.0"?>
- <!--
- Full Screen Canvas
-
- Usage:
- window.fullScreenCanvas.show();
- ... // do something
- window.fullScreenCanvas.hide();
- var zoom = window.fullScreenCanvas.getZoomForFrame(window.content);
-
- lisence: The MIT License, Copyright (c) 2009 SHIMODA "Piro" Hiroshi
- http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/license.txt
- original:
- http://www.cozmixng.org/repos/piro/fx3-compatibility-lib/trunk/fullScreenCanvas.xul
- -->
- <overlay xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
- <script type="application/x-javascript"><![CDATA[
-
- window.addEventListener('DOMContentLoaded', function() {
- window.removeEventListener('DOMContentLoaded', arguments.callee, true);
-
- const currentRevision = 8;
- var root = document.documentElement;
-
- var loadedRevision = root.getAttribute('fullScreenCanvas');
- if (loadedRevision) {
- loadedRevision = Number(loadedRevision);
- if (loadedRevision >= currentRevision) {
- return;
- }
- else if (loadedRevision < currentRevision) {
- root.setAttribute('fullScreenCanvas', currentRevision);
- window.fullScreenCanvas.destroy();
- }
- }
-
- window.fullScreenCanvas = {
- show : function(aTargetElement)
- {
- if (this.shown) return;
- this.shown = true;
-
- var color = '-moz-field';
- var canvas = this.canvas;
- if (!canvas) return;
-
- var rootBox = document.documentElement.boxObject;
- var canvasW = window.innerWidth;
- var canvasH = window.innerHeight;
-
- var x, y, w, h;
- if (aTargetElement && aTargetElement.ownerDocument == document) {
- var box = aTargetElement.boxObject;
- y = box.screenY - rootBox.screenY;
- x = box.screenX - rootBox.screenX;
- w = box.width;
- h = box.height;
- }
- else {
- x = y = 0;
- w = canvasW;
- h = canvasH;
- }
-
- canvas.style.left = 0;
- canvas.style.top = 0;
- canvas.style.width = (canvas.width = canvasW)+'px';
- canvas.style.height = (canvas.height = canvasH)+'px';
- canvas.style.zIndex = 65000;
- var frame = this.frame;
- if (frame) {
- frame.style.width = canvas.style.width;
- frame.style.height = canvas.style.height;
- }
- try {
- var ctx = canvas.getContext('2d');
- ctx.clearRect(0, 0, canvasW, canvasH);
- ctx.save();
- ctx.translate(x, y);
- ctx.drawWindow(window, x, y, w, h, color);
- ctx.restore();
-
- var browsers = this.browsers;
- var self = this;
- browsers.forEach(function(aBrowser) {
- try {
- var b = aBrowser;
- if (b.localName == 'subbrowser') b = b.browser;
- var TST = b.treeStyleTab;
- var frame = b.contentWindow;
- var zoom = self.getZoomForFrame(frame);
- var x = (b.localName == 'tabbrowser' ? b.mCurrentBrowser : b ).boxObject.x;
- var y = (b.localName == 'tabbrowser' ? b.mCurrentBrowser : b ).boxObject.y;
- var w = frame.innerWidth;
- var h = frame.innerHeight;
- var dx = 0;
- var dy = 0;
- if (
- TST &&
- TST.autoHideEnabled &&
- ('autoHideShown' in TST ?
- TST.autoHideShown :
- TST.tabbarShown
- )
- ) {
- var pos = b.getAttribute(TST.kTABBAR_POSITION);
- var xOffset = 'autoHideXOffset' in TST ? TST.autoHideXOffset : TST.tabbarWidth ;
- var yOffset = 'autoHideYOffset' in TST ? TST.autoHideYOffset : TST.tabbarHeight ;
- switch (pos)
- {
- case 'left':
- dx = xOffset / zoom;
- w -= xOffset / zoom;
- break;
- case 'right':
- x += xOffset / zoom;
- w -= xOffset / zoom;
- break;
- case 'top':
- dy = yOffset / zoom;
- h -= yOffset / zoom;
- break;
- case 'bottom':
- y += yOffset / zoom;
- h -= yOffset / zoom;
- break;
- }
- }
- ctx.save();
- ctx.translate(x, y);
- ctx.save();
- ctx.scale(zoom, zoom);
- ctx.drawWindow(frame, dx+frame.scrollX, dy+frame.scrollY, w, h, color);
- ctx.restore();
- ctx.restore();
- }
- catch(e) {
- }
- });
-
- canvas.style.position = 'fixed';
- this.container.removeAttribute('collapsed');
- }
- catch(e) {
- this.container.setAttribute('collapsed', true);
- }
- },
- shown : false,
-
- getZoomForFrame : function(aFrame)
- {
- const Prefs = Components
- .classes['@mozilla.org/preferences;1']
- .getService(Components.interfaces.nsIPrefBranch);
- try {
- if (Prefs.getBoolPref('browser.zoom.full')) {
- var zoom = aFrame
- .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
- .getInterface(Components.interfaces.nsIWebNavigation)
- .QueryInterface(Components.interfaces.nsIDocShell)
- .contentViewer
- .QueryInterface(Components.interfaces.nsIMarkupDocumentViewer)
- .fullZoom;
- return (zoom * 1000 % 1) ? zoom+0.025 : zoom ;
- }
- }
- catch(e) {
- }
- return 1;
- },
-
- hide : function()
- {
- if (!this.shown) return;
- var canvas = this.canvas;
- canvas.style.position = 'static';
- canvas.style.width = canvas.style.height = canvas.style.zIndex = 0;
- this.container.setAttribute('collapsed', true);
- this.shown = false;
- },
-
- get browsers()
- {
- browsers = [].concat(Array.slice(document.getElementsByTagName('tabbrowser')))
- .concat(Array.slice(document.getElementsByTagName('browser')));
- if ('SplitBrowser' in window) browsers = browsers.concat(SplitBrowser.browsers);
- if (this.frame) {
- var index = browsers.indexOf(this.frame);
- browsers.splice(index, 1);
- }
- return browsers;
- },
-
- get frame()
- {
- return document.getElementById('fullScreenCanvas-frame');
- },
-
- get canvas()
- {
- if (!this.frame) return this._canvas;
-
- var doc = this.frame.contentDocument;
- var canvas = doc.getElementById('fullScreenCanvas-canvas');
- if (canvas) return canvas;
-
- canvas = doc.importNode(this._canvas.cloneNode(true), true);
- var root = doc.documentElement;
- root.setAttribute('style', 'overflow: none; margin: 0;padding: 0;');
- while (root.hasChildNodes())
- {
- root.removeChild(root.firstChild);
- }
- root.appendChild(canvas);
- return canvas;
- },
- _canvas : null,
-
- get container()
- {
- return document.getElementById('fullScreenCanvas-container');
- },
-
- init : function() {
- var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
- canvas.setAttribute('id', 'fullScreenCanvas-canvas');
- canvas.setAttribute('width', '0');
- canvas.setAttribute('height', '0');
- canvas.setAttribute('style', 'width:0;height:0;');
- this._canvas = canvas;
- if (!this.isGecko19) {
- this.container.appendChild(canvas);
- return
- }
- /* We have to put canvas into a frame because Gecko 1.9
- renders canvas under the main content area if it is
- not in a frame.
- */
- var frame = document.createElement('browser');
- frame.setAttribute('id', 'fullScreenCanvas-frame');
- frame.setAttribute('disablehistory', 'true');
- this.container.appendChild(frame);
- frame.style.width = 0;
- frame.style.height = 0;
- frame.style.borderWidth = 0;
- frame.style.margin = 0;
- frame.style.padding = 0;
- },
-
- get isGecko19()
- {
- const XULAppInfo = Components.classes['@mozilla.org/xre/app-info;1']
- .getService(Components.interfaces.nsIXULAppInfo);
- var version = XULAppInfo.platformVersion.split('.');
- return parseInt(version[0]) >= 2 || parseInt(version[1]) >= 9;
- },
-
- destroy : function() {
- var range = document.createRange();
- range.selectNodeContents(this.container);
- range.deleteContents();
- range.detach();
- }
- };
-
- fullScreenCanvas.init();
- }, true);
-
- ]]></script>
-
- <window id="main-window">
- <vbox id="fullScreenCanvas-container"
- collapsed="true"
- style="
- position: fixed;
- z-index: 60000;
- top: 0;
- left: 0;
- "
- onclick="fullScreenCanvas.hide();"/>
- </window>
-
- </overlay>
-